<?php 
$page_security = 'SA_SALESMAN';
$path_to_root = "..";
include($path_to_root . "/includes/session.inc");

page(_($help_context = "Transaksi Kas Kecil"));

include($path_to_root . "/includes/ui.inc");
include("/includes/db/pittycash_db.inc");
simple_page_mode(true);
//------------------------------------------------------------------------------------------------

if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
{

	//initialise no input errors assumed initially before we test
	$input_error = 0;

	if (strlen($_POST['empname']) == 0)
	{
		$input_error = 1;
		display_error(_("The employee name cannot be empty."));
		set_focus('empname');
	}
	
	//$pr1 = check_num('provision', 0,100);
	//if (!$pr1 || !check_num('provision2', 0, 100)) {
	//	$input_error = 1;
	//	display_error( _("Salesman provision cannot be less than 0 or more than 100%."));
	//	set_focus(!$pr1 ? 'provision' : 'provision2');
	//}
	//if (!check_num('break_pt', 0)) {
	//	$input_error = 1;
	//	display_error( _("Salesman provision breakpoint must be numeric and not less than 0."));
	//	set_focus('break_pt');
	//}
	
	if ($input_error != 1)
	{
    	if ($selected_id != -1) 
    	{
    		/*selected_id could also exist if submit had not been clicked this code would not run in this case cos submit is false of course  see the delete code below*/
			update_employee($selected_id, $_POST['empname'], $_POST['typeid'], $_POST['phone'], $_POST['address'], $_POST['email']);
				
    	}
    	else
    	{
    		/*Selected group is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Sales-person form */
			add_employee($_POST['empname'], $_POST['typeid'], $_POST['phone'], $_POST['address'], $_POST['email']);
    	}

    	if ($selected_id != -1) 
			display_notification(_('Selected employee data have been updated'));
		else
			display_notification(_('New employee data have been added'));
		$Mode = 'RESET';
	}
}
if ($Mode == 'Delete')
{
	//the link to delete a selected record was clicked instead of the submit button

	// PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'

	delete_employee($selected_id);
	display_notification(_('Selected employee data have been deleted'));
	
	$Mode = 'RESET';
}

if ($Mode == 'RESET')
{
	$selected_id = -1;
	$sav = get_post('show_inactive');
	unset($_POST);
	$_POST['show_inactive'] = $sav;
}
//------------------------------------------------------------------------------------------------

$result = get_kas_bon_non_journal();

start_form();
start_table(TABLESTYLE, "width=75%");
$th = array(_("No. Kas Bon"), _("No. Nota"),_("Tanggal Kasbon"),_("Total Nilai Faktur"),_("Kode Rekening Beban"),_("Rekening Beban"));
inactive_control_column($th);
table_header($th);

$k = 0;

while ($myrow = db_fetch($result))
{

	alt_table_row_color($k);

    label_cell($myrow["ref"]);
   	label_cell($myrow["no_note"]); 
	label_cell($myrow["date"]);
	label_cell(price_format($myrow["amount"]),"align=right");	 	  	
	label_cell($myrow["acc_id"]);
	label_cell($myrow["account_name"]);
// 	edit_button_cell("Edit".$myrow["pittycashid"], _("Edit"));
// 	delete_button_cell("Delete".$myrow["pittycashid"], _("Delete"));
  	end_row();

} //END WHILE LIST LOOP

//inactive_control_row($th);
end_table();
echo '<br>';

//------------------------------------------------------------------------------------------------

if ($selected_id != -1) 
{
 	if ($Mode == 'Edit') {
		//editing an existing Sales-person
		$myrow = get_employee($selected_id);

		$_POST['empname'] = $myrow["empname"];
		$_POST['phone'] = $myrow["phone"];
		$_POST['address'] = $myrow["address"];
		$_POST['email'] = $myrow["email"];
		$_POST['typeid'] = $myrow["typeid"];
	}
	hidden('selected_id', $selected_id);
} 

start_table(TABLESTYLE2);

text_row_ex(_("Employee Name:"), 'empname', 30);
amount_row(_("Amount:"), 'amount');
textarea_row(_("Memo:"), 'note', null, 22, 4);
end_table(1);

		if (isset($_POST['trans_no']) && $_POST['trans_no'] > 0 )
			submit_center('AddPaymentItem', _("Update Payment"), true, '', 'default');
		else
			submit_center('AddPaymentItem', _("Add Transaction"), true, '', 'default');
//submit_add_or_update_center($selected_id == -1, '', 'both');

end_form();

end_page();

?>